package com.seuic.hnapps.util;

import com.orhanobut.logger.Logger;
import com.seuic.hnapps.bean.CardBinInfo_bean;
import com.solab.enc.DES3;
import com.solab.iso8583.IsoMessage;
import com.solab.iso8583.IsoType;

import java.util.List;

/**
 * 身份核实 联网核查
 */
public class IVNInterface {
    public IsoMessage packRequest(String transn,  String passWord,
                                  List<CardBinInfo_bean> beans, String CardType, String track2Data,
                                  String track3Data, String id_type, String id_num, String s_number,
                                  String Field55) {
        IsoMessage msg = new IsoMessage();
        String encflag = Constants.YANTAI_ENCFLG2;
        msg.setType(0x0100);
        msg.setHeadValue(1, String.valueOf(Constants.ATMP_HEADER_LENGTH), IsoType.BCD, 2);
        msg.setHeadValue(2, Constants.YANTAI_PACKVS, IsoType.ALPHA, 2);
        msg.setHeadValue(3, Constants.YANTAI_TERMVS, IsoType.ALPHA, 8);
        msg.setHeadValue(4, encflag, IsoType.ALPHA, 1); // 加密标志：业务交易，公网传输1-报文加密，专线传输2-磁道加密
        msg.setHeadValue(5, Constants.YANTAI_BANKID, IsoType.ALPHA, 8);
        msg.setHeadValue(6, Constants.YANTAI_TERMNO, IsoType.ALPHA, 8);
        msg.setHeadValue(7, "0000", IsoType.ALPHA, 4); // 8583域部分长度，组包时动态填充


        msg.setValue(3, "550000", IsoType.ALPHA, 6);
        msg.setValue(7, DateUtil.getCurrentTime(DateUtil.M_TIME_PATTERN), IsoType.ALPHA, 10);
        msg.setValue(8, Constants.YANTAI_CHANLENO, IsoType.ALPHA, 2);
        msg.setValue(11, transn, IsoType.ALPHA, 6);

        msg.setValue(20, "00000000", IsoType.ALPHA, 8);
        // 第22域，需要严格按照规范填写 手工输入01 磁条读取02 IC卡 05 第三位是否有密码1 无密码2
        String f22 = "";
        if (CardType.equals("MAG Card")) {
            f22 = "02";
        } else if (CardType.equals("IC Card")) {
            f22 = "05";
        } else {
            f22 = "01";
        }
        msg.setValue(22, f22 + 1, IsoType.ALPHA, 3);
        msg.setValue(41, Constants.YANTAI_TERMNO, IsoType.ALPHA, 8);
        msg.setValue(48, Constants.YANTAI_TERMNO, IsoType.ALPHA, 8);



        // 第57域，终端各部件状态，按实际填写
        msg.setValue(57, Constants.YANTAI_F57, IsoType.LLLVAR, 127);
        // 第60域，按实际填写
        msg.setValue(60, Constants.YANTAI_BATCHNO + "6" + "0", IsoType.LLVAR, 30);
        // MAC，填写8字节，则需要生成MAC，外层统一处理；本域不填写，则外层不会生成
        msg.setValue(128, "00000000", IsoType.ALPHA, 8);

        return msg;
    }
}
